﻿using Aishow.BLL;
using Aishow.IBLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Aishow.Website
{
    public partial class Mobile : System.Web.UI.Page
    {
        IAccountManager AccountManager = new AccountManager();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {

            if (Page.IsValid)
            {

                var result = AccountManager.LoginByMobileNumber(txtMobileNumber.Text, txtPassword.Text);
                if (result.StatusCode == Model.OperResult.StatusCode.Succeed)
                {
                    var user = result.ReadResult();
                    IdentityManager.SaveUser(user);
                    var url = Request.QueryString["ReturnUrl"];
                    if (string.IsNullOrWhiteSpace(url)==false)
                    {
                        Response.Redirect(url);
                    }
                    else
                    {
                        Response.Redirect("Default.aspx");
                    }

                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "loginerror", $"alert('{result.Message}',)", true);
                }
            }
        }
    }
}